package host.abetsy.recast.tools;

import cn.hutool.core.io.FileUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class FilePathTool {

    public static List<File> getAllSubDirectories(String path) {
        return getAllSubDirectories(new File(path));
    }

    private static List<File> getAllSubDirectories(File dir) {
        List<File> directSubDirs = getDirectSubDirectories(dir.getAbsolutePath());
        List<File> allDirectories = new ArrayList<>(directSubDirs);
        for (File subDir : directSubDirs) {
            allDirectories.addAll(getAllSubDirectories(subDir));
        }
        return allDirectories;
    }

    public static List<File> getDirectSubDirectories(String path) {
        List<File> allItems = Arrays.asList(FileUtil.ls(path));
        return allItems.stream()
                .filter(File::isDirectory)
                .collect(Collectors.toList());
    }

}
